package com.print.ane
{
	import flash.external.ExtensionContext;
	import flash.filesystem.File;

	public class PrintAne
	{
		
		private var context:ExtensionContext;
		

		
		public function PrintAne()
		{
			trace("初始化ANE");
			try{
				context = ExtensionContext.createExtensionContext("com.print.ane.PrintAne","");
			}catch(error:Error){
				trace("出现错误   " + error.getStackTrace());
			}
		}
		
		/** 检查是否安装了PrintShare **/
		public function isPrintShareInstalled(packet:String):Boolean{
			var isinstalled:Boolean = isinstalled = context.call("check",packet);
			if(isinstalled)
			{
				return true;
			}
			return false;
		}
		
		/** 安装PrintShare **/
		public function installPrintShare(apk:File):Boolean{
			if(!apk.exists || apk.isDirectory){
				return false;
			}
			var isOK:Boolean = context.call("install",apk.nativePath);
			if(isOK)
			{
				return true;
			}
			return false;
		}
		
		
		/** 打印一个文件 **/
		public function printFile(mete:String,packet:String,activity:String,file:File):Boolean{
			if(!file.exists || file.isDirectory){
				return false;
			}
			var isOK:Boolean = context.call("printfile",mete,packet,activity,file.nativePath);
			if(isOK)
			{
				return true;
			}
			return false;
		}
		
	}
}